package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.ApartmentInfo;
import com.atguigu.lease.model.entity.ViewAppointment;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.app.mapper.ApartmentLabelMapper;
import com.atguigu.lease.web.app.mapper.GraphInfoMapper;
import com.atguigu.lease.web.app.mapper.RoomInfoMapper;
import com.atguigu.lease.web.app.mapper.ViewAppointmentMapper;
import com.atguigu.lease.web.app.service.ApartmentInfoService;
import com.atguigu.lease.web.app.service.ViewAppointmentService;
import com.atguigu.lease.web.app.vo.apartment.ApartmentItemVo;
import com.atguigu.lease.web.app.vo.appointment.AppointmentDetailVo;
import com.atguigu.lease.web.app.vo.appointment.AppointmentItemVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @author liubo
 * @description 针对表【view_appointment(预约看房信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */

/**
 * @author wxs
 * @description 针对表【view_appointment(预约看房信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
        implements ViewAppointmentService {
    @Autowired
    private ViewAppointmentMapper viewAppointmentMapper;
    @Autowired
    private ApartmentInfoService apartmentInfoService;
    @Autowired
    private ApartmentLabelMapper apartmentLabelMapper;
    @Autowired
    private GraphInfoMapper graphInfoMapper;
    @Autowired
    private RoomInfoMapper roomInfoMapper;

    @Override
    public List<AppointmentItemVo> listByUserId(Long userId) {

        return viewAppointmentMapper.listByUserId(userId, ItemType.ROOM);
    }

    @Override
    public AppointmentDetailVo getDetailById(Long id) {
        ViewAppointment viewAppointment = this.getById(id);
        if(ObjectUtils.isEmpty(viewAppointment)){
            return null;
        }
        AppointmentDetailVo appointmentDetailVo=new AppointmentDetailVo();
        BeanUtils.copyProperties(viewAppointment,appointmentDetailVo);
        //查预约信息以及公寓对象，标签列表，图片列表，价格
        ApartmentItemVo apartmentItemVo=new ApartmentItemVo();

        //公寓对象
        ApartmentInfo apartmentInfo = apartmentInfoService.getById(viewAppointment.getApartmentId());
        BeanUtils.copyProperties(apartmentInfo,apartmentItemVo);
        //图片列表
        apartmentItemVo.setGraphVoList(graphInfoMapper.graphListByItem(viewAppointment.getApartmentId(),ItemType.APARTMENT));
        //标签列表
        apartmentItemVo.setLabelInfoList(apartmentLabelMapper.queryListByApartmentId(viewAppointment.getApartmentId()));
        //价格
        apartmentItemVo.setMinRent(roomInfoMapper.getminRentByApartId(viewAppointment.getApartmentId()));

        appointmentDetailVo.setApartmentItemVo(apartmentItemVo);

        return appointmentDetailVo;
    }

}




